package karileet.meeting.profile.list.adapter;

import java.util.List;

import karileet.meeting.profile.list.holder.ListItemHolder;
import karileet.meeting.profile.list.item.ListItem;

import karileet.meeting.profile.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListItemAdapter extends ArrayAdapter<ListItem> {

	  private final List<ListItem> list;
	  private final Activity context;

	  public ListItemAdapter(Activity context, List<ListItem> list) {
	    super(context, R.layout.list_item, list);
	    this.context = context;
	    this.list = list;
	  }
	  
	  
	  @Override
	  public View getView(int position, View convertView, ViewGroup parent) {
		  View view = null;
		  if (convertView == null) {
			  LayoutInflater inflator = context.getLayoutInflater();
		      view = inflator.inflate(R.layout.list_item, null);
			  final ListItemHolder holder = new ListItemHolder();
			  
			  holder.setTitle((TextView) view.findViewById(R.id.rowTitle));
			  holder.setDescription((TextView) view.findViewById(R.id.rowDescription));
			  
			  view.setTag(holder);
			  holder.setTag(list.get(position));
		  } else {
			  view = convertView;
			  //something i do not understand is omitted
			  
		  }
		  ListItemHolder holder = (ListItemHolder) view.getTag();
		  holder.setTitleText(list.get(position).getTitle());
		  holder.setDescriptionText(list.get(position).getDescription());
		  
		  return view;
	  }
}
